<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>

</body>
<script>
    function trim(str) {
        return str.replace(/\s*/g, '');
    }

    var trim = function (str) {
        return str.replace(/\s*/g, "");
    }
    str.replace(/\s*/g, ""); //去除字符串内所有的空格
    str.replace(/^\s*|\s*$/g, ""); //去除字符串内两头的空格
    str.replace(/^\s*/, ""); //去除字符串内左侧的空格
    str.replace(/(\s*$)/g, ""); //去除字符串内右侧的空格

    console.log(trim('     wqdw  dq    awda  wda  '));
    console.log('1');
</script>

</html>